home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / fmodla13.zip / FILESYST.DEF < prev    next >
Text File  |  1992-01-29  |  4KB  |  147 lines

  1. DEFINITION MODULE FileSystem;
  2.  
  3. (* (C) Copyright 1987 Fitted Software Tools. All rights reserved. *)
  4.  
  5. (*
  6.     This module provides routines for file handling similar to the ones
  7.     described in the book "Programming in Modula-2" by Niklaus Wirth.
  8. *)
  9.  
  10. FROM SYSTEM IMPORT WORD, ADDRESS;
  11.  
  12. TYPE
  13.     FDPtr;  (* for internal use only *)
  14.  
  15.     Response = ( done, notdone );
  16.     IOMode   = ( read, write, io );
  17.     File = RECORD
  18.         id      :INTEGER;
  19.         res     :Response;
  20.         eof     :BOOLEAN;
  21.         mode    :IOMode;
  22.         fdptr   :FDPtr;     (* for internal use only *)
  23.     END;
  24.  
  25. (*
  26.     All the procedures will set File.res to 'done' if the call succeeds
  27.     and to 'notdone' otherwise.
  28.  
  29.     File.eof is TRUE after a new file is created or when one of the Read
  30.     operations is attempted and there is no more data to read.
  31. *)
  32.  
  33.  
  34. PROCEDURE Lookup( VAR f :File; filename :ARRAY OF CHAR; new :BOOLEAN );
  35. (*
  36.     Open the file named in filename.
  37.     IF the file does not exist THEN
  38.         IF new THEN create a new file
  39.         ELSE fail
  40.  
  41.     Lookup always tries to open the file for io first; if that fails,
  42.     it tries to open the file for reading.
  43.     f.mode will be set according to how the file was opened.
  44. *)
  45.  
  46. PROCEDURE Create( VAR f :File; mediumname :ARRAY OF CHAR );
  47. (*
  48.     Create a new temporary file.
  49.     If mediumname matches a variable in the environment, the
  50.     value of that variable is assumed to be the path to where
  51.     the file is to be created.
  52. *)
  53.  
  54. PROCEDURE Close( VAR f :File );
  55. (*
  56.     close the file.
  57.     if the file was Rename'd, the directory entry is modified
  58.     at this time; if necessary (the file was renamed to a different
  59.     drive), the file is copied!
  60. *)
  61.  
  62. PROCEDURE Reset( VAR f :File );
  63. (*
  64.     Set the file pointer to the beginning of the file.
  65. *)
  66.  
  67. PROCEDURE Rewrite( VAR f :File );
  68. (*
  69.     Set the file pointer to the beginning of the file and truncate
  70.     the file (make it empty).
  71. *)
  72.  
  73. PROCEDURE Rename( VAR f :File; filename :ARRAY OF CHAR );
  74. (*
  75.     change the name of the file f to filename.
  76.     a file can be Rename'd (moved) to a different drive and/or pathname.
  77.     NOTE: the directory entry is not modified until the file is closed.
  78. *)
  79.  
  80. PROCEDURE ReadWord( VAR f :File; VAR w :WORD );
  81. (*
  82.     read a WORD from the file
  83. *)
  84.  
  85. PROCEDURE WriteWord( VAR f :File; w :WORD );
  86. (*
  87.     write a WORD to the file
  88. *)
  89.  
  90. PROCEDURE ReadChar( VAR f :File; VAR ch :CHAR );
  91. (*
  92.     read a character from the file.
  93.     the character ASCII.CR is converted to ASCII.EOL and ASCII.LF is ignored.
  94. *)
  95.  
  96. PROCEDURE WriteChar( VAR f :File; ch :CHAR );
  97. (*
  98.     write the character ch to the file.
  99.     ASCII.EOL is converted to the sequence ASCII.CR ASCII.LF.
  100. *)
  101.  
  102. PROCEDURE GetPos( VAR f :File; VAR highpos, lowpos :CARDINAL );
  103. (*
  104.     return the current position of the file pointer
  105. *)
  106.  
  107. PROCEDURE SetPos( VAR f :File; highpos, lowpos :CARDINAL );
  108. (*
  109.     move the file pointer to position highpos*65536+lowpos
  110. *)
  111.  
  112. PROCEDURE GetLPos( VAR f :File; VAR pos :LONGCARD );
  113. (*
  114.     return the current position of the file pointer
  115. *)
  116.  
  117. PROCEDURE SetLPos( VAR f :File; pos :LONGCARD );
  118. (*
  119.     move the file pointer to pos.
  120. *)
  121.  
  122. PROCEDURE Length( VAR f :File; VAR highlen, lowlen :CARDINAL );
  123. (*
  124.     return the size of the file
  125. *)
  126.  
  127. PROCEDURE LLength( VAR f :File; VAR length :LONGCARD );
  128. (*
  129.     return the size of the file
  130. *)
  131.  
  132. PROCEDURE ReadNBytes( VAR f :File; buffPtr :ADDRESS; n :CARDINAL;
  133.                       VAR nRead :CARDINAL );
  134. (*
  135.     try to read n number of bytes.
  136.     On return, nRead is the actual number of bytes read.
  137. *)
  138.  
  139. PROCEDURE WriteNBytes( VAR f :File; buffPtr :ADDRESS; n :CARDINAL;
  140.                        VAR nWritten :CARDINAL );
  141. (*
  142.     write n bytes to the file.
  143.     On return nWritten is the actual number of bytes that were written.
  144. *)
  145.  
  146. END FileSystem.
  147.